#jinja2: trim_blocks: False
services:
  {%- if playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names %}
  jingwei-dm-redis:
    image: {{ jingwei_redis_image }}
    container_name: jingwei-dm-redis
    restart: unless-stopped
    {%- if network_mode is not defined or network_mode == "" %}
    ports:
      - {{ expose_redis_port }}:6379
    {%- endif %}
    {%- if network_mode is defined and network_mode %}
    network_mode: {{ network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
    volumes:
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
      - {{ anbao_redis_data_dir }}:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
  {%- endif %}
  {%- if deploy_es and (playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names) %}
  jingwei-es:
    image: {{ jingwei_es_image }}
    container_name: jingwei-es
    restart: unless-stopped
    {%- if network_mode is not defined or network_mode == "" %}
    ports:
      - {{ expose_es_web_port }}:9200
      - {{ expose_es_rpc_port }}:9300
    {%- endif %}
    {%- if network_mode is defined and network_mode %}
    network_mode: {{ network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    volumes:
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
      - {{ anbao_es_data_dir }}:/usr/share/elasticsearch/data
      - {{ anbao_es_plugins_dir }}:/usr/share/elasticsearch/plugins
      - {{ anbao_es_logs_dir }}:/usr/share/elasticsearch/logs
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xms4g -Xmx4g"
      http.host: 0.0.0.0
      xpack.security.enabled: true
      ELASTIC_PASSWORD: {{ es_password }}
  {%- endif %}
  {%- if deploy_db_data | bool and deploy_db_primary_data | bool and (playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names) %}
  jingwei-dm8:
    image: {{ jingwei_dm_db_image }}
    container_name: jingwei-dm8
    restart: unless-stopped
    {%- if dm_network_mode is not defined or dm_network_mode == "" %}
    ports:
      - {{ expose_dm_db_port }}:5237
    {%- endif %}
    {%- if dm_network_mode is defined and dm_network_mode %}
    network_mode: {{ dm_network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    volumes:
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
      - /opt/anbao/db/primary/dm:/dmdata/data
      - /opt/anbao/running/healthcheck.sh:/opt/dmdbms/bin/healthcheck.sh
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      PAGE_SIZE: 16
      LD_LIBRARY_PATH: /home/dmdba/dmdbms/bin
      EXTENT_SIZE: 32
      BLANK_PAD_MODE: 1
      LOG_SIZE: 1024
      UNICODE_FLAG: 1
      CASE_SENSITIVE: 0
      INSTANCE_NAME: anbao_dm8
      SYSDBA_PWD: SYSDBA001
      {%- if deploy_db_standby_data | bool %}
      MODE: docker_dmwatcher
      DMWATCHER_ROLE: primary
      DW_NO: 1
      CLUSTER_IPS: "{{ server_docker_dm_node_ips }}"
      {%- endif %}
    healthcheck:
      test: ['CMD', '/opt/dmdbms/bin/healthcheck.sh']
      interval: 10s
      timeout: 5s
      retries: 5
  {%- endif %}
  {%- if deploy_db_data | bool and deploy_db_standby_data | bool and (playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names) %}
  jingwei-dm8-standby:
    image: {{ jingwei_dm_db_image }}
    container_name: jingwei-dm8-standby
    restart: unless-stopped
    {%- if dm_network_mode is not defined or dm_network_mode == "" %}
    ports:
      - {{ expose_dm_db_port }}:5237
    {%- endif %}
    {%- if dm_network_mode is defined and dm_network_mode %}
    network_mode: {{ dm_network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    volumes:
      - /etc/localtime:/etc/localtime
      - /etc/timezone:/etc/timezone
      - /opt/anbao/db/standby/dm:/dmdata/data
      - /opt/anbao/running/healthcheck.sh:/opt/dmdbms/bin/healthcheck.sh
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      PAGE_SIZE: 16
      LD_LIBRARY_PATH: /home/dmdba/dmdbms/bin
      EXTENT_SIZE: 32
      BLANK_PAD_MODE: 1
      LOG_SIZE: 1024
      UNICODE_FLAG: 1
      CASE_SENSITIVE: 0
      INSTANCE_NAME: anbao_dm8
      SYSDBA_PWD: SYSDBA001
      {%- if deploy_db_standby_data | bool %}
      MODE: docker_dmwatcher
      DMWATCHER_ROLE: standby
      DW_NO: 2
      CLUSTER_IPS: "{{ server_docker_dm_node_ips }}"
      {%- endif %}
    healthcheck:
      test: ['CMD', '/opt/dmdbms/bin/healthcheck.sh']
      interval: 10s
      timeout: 5s
      retries: 5
  {%- endif %}
  {%- if deploy_db_data | bool and deploy_db_monitor_data | bool and (playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names) %}
  jingwei-dm8-monitor:
    image: {{ jingwei_dm_db_image }}
    container_name: jingwei-dm8-monitor
    restart: unless-stopped
    {%- if dm_network_mode is not defined or dm_network_mode == "" %}
    ports:
      - {{ expose_dm_db_monitor }}:{{ monitor_dm_port }}
    {%- endif %}
    {%- if dm_network_mode is defined and dm_network_mode %}
    network_mode: {{ dm_network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    volumes:
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime
      - /opt/anbao/db/monitor/dm:/dmdata/data
      - /opt/anbao/running/healthcheck.sh:/opt/dmdbms/bin/healthcheck.sh
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      PAGE_SIZE: 16
      LD_LIBRARY_PATH: /home/dmdba/dmdbms/bin
      EXTENT_SIZE: 32
      BLANK_PAD_MODE: 1
      LOG_SIZE: 1024
      UNICODE_FLAG: 1
      CASE_SENSITIVE: 0
      INSTANCE_NAME: anbao_dm8
      SYSDBA_PWD: SYSDBA001
      {%- if deploy_db_monitor_data | bool %}
      MODE: docker_dmwatcher
      DMWATCHER_ROLE: monitor
      CLUSTER_IPS: "{{ server_docker_dm_node_ips }}"
      {%- endif %}
    healthcheck:
      test: ['CMD', '/opt/dmdbms/bin/healthcheck.sh']
      interval: 10s
      timeout: 5s
      retries: 5
  {%- endif %}
  {%- if playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_server_node' in group_names %}
  jingwei-backend:
    image: {{ jingwei_backend_image }}
    container_name: jingwei-backend
    privileged: true
    entrypoint: java -Dspring.config.location=/opt/anbao/project/config/application.yml,/opt/anbao/project/config/application-prod.yml -Dserver.port=8080 -jar jingwei-admin.jar
    restart: unless-stopped
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      UPLOAD_JINGWEI_PATH: /opt/anbao/project/common
      DB_NAME: {{ docker_dm_db_user }}
      DB_USER: {{ docker_dm_db_user }}
      DB_PASS: {{ docker_dm_db_default_password }}
      {%- if jw_redis_host is defined and is_host_deploy %}
      DB_REDIS_HOST: {{ jw_redis_host }}
      {%- endif %}
      DB_REDIS_PORT: {{ expose_redis_port }}
    depends_on:
      {%- if deploy_db_data | bool and deploy_db_primary_data | bool %}
      - jingwei-dm8
      {%- elif deploy_db_data | bool and deploy_db_standby_data | bool %}
      - jingwei-dm8-standby
      {%- elif deploy_db_data | bool and deploy_db_monitor_data | bool %}
      - jingwei-dm8-monitor
      {%- endif %}
      - jingwei-dm-redis
    {%- if network_mode is not defined or network_mode == "" %}
    ports:
      - {{ expose_backend_port }}:8080
    {%- endif %}
    volumes:
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime
      - /opt/anbao/project/common:/opt/anbao/project/common
      - /opt/anbao/project/config:/opt/anbao/project/config
      - /opt/anbao/map:/opt/anbao/map
      - /opt/anbao/project/GISKey.lic:/jingwei/server/GISKey.lic
      - /opt/anbao/project/jingwei-admin.jar:/jingwei/server/jingwei-admin.jar
      - /data:/data
      - /:/fakeRoot
      - /opt/anbao/map/root/media:/usb
    {%- if network_mode is defined and network_mode %}
    network_mode: {{ network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    deploy:
      resources:
        limits:
          cpus: '0.8'
          memory: 2048M
        reservations:
          cpus: '0.5'
          memory: 1500M
  {%- endif %}
  jingwei-frontend:
    image: {{ jingwei_frontend_image }}
    container_name: jingwei-frontend
    privileged: true
    restart: unless-stopped
    {%- if not (playbook_name == 'serverclient' and 'jw_client_node' in group_names) %}
    depends_on:
      - jingwei-backend
    {%- endif %}
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
    {%- if network_mode is not defined or network_mode == "" %}
    ports:
      - {{ expose_frontend_http_port }}:80
      - {{ expose_frontend_https_port }}:443
    {%- endif %}
    {%- if network_mode is defined and network_mode %}
    network_mode: {{ network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    volumes:
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime
      - /opt/anbao/map:/opt/anbao/map
      - /opt/anbao/qgz:/opt/anbao/qgz
      - /data:/data
      - /:/fakeRoot
      - /opt/anbao/map/root/media:/usb
      - /opt/anbao/running/bind.ini:/usr/local/openresty/nginx/conf/bind.ini
      # 证书映射
      # - /opt/anbao/project/cert:/etc/nginx/cert
      - /opt/anbao/running/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
      - /opt/anbao/running/default.conf:/etc/nginx/conf.d/default.conf
      - /opt/anbao/running/dist:/usr/local/openresty/nginx/html
      - /opt/anbao/project/web/SCMAP:/opt/anbao/project/web/SCMAP
      - /opt/anbao/project/common:/opt/anbao/project/common
    ulimits:
      nofile:
        soft: 65535
        hard: 65535
  {%- if playbook_name == 'standalone' or playbook_name == 'serverclient' and 'jw_client_node' in group_names %}
  jingwei-printer:
    image: {{ jingwei_printer_image }}
    container_name: jingwei-printer
    restart: unless-stopped
    {%- if (playbook_name == 'standalone' and 'jw_server_node' in group_names) %}
    depends_on:
      - jingwei-backend
    {%- endif %}
    privileged: true
    environment:
      TZ: Asia/Shanghai
      TimeZone: Asia/Shanghai
      SET_CONTAINER_TIMEZONE: true
      CONTAINER_TIMEZONE: Asia/Shanghai
      DISPLAY: "unix$DISPLAY" # ":0"
      QT_QPA_PLATFORM: "{{ 'xcb' if have_nvidia_driver else 'offscreen' }}" # "offscreen" "xcb"
      {%- if have_nvidia_driver %}
      NVIDIA_DRIVER_CAPABILITIES: "all"
      NVIDIA_VISIBLE_DEVICES: "all"
      {%- endif %}
      XDG_RUNTIME_DIR: "/tmp/runtime-root"
      JINGWEI_SERVER_HOST: "{{ xserver_host }}"
      JINGWEI_SERVER_PORT: {{ expose_backend_port }}
      MAPPING_EXPORT_NGINX_HOST: "{{ mapping_export_nginx_host }}"
      MAPPING_EXPORT_NGINX_PORT: {{ expose_frontend_http_port }}
      MAP_BASE_URL: "http://{{ main_ip if (network_mode | default('')) == '' else frontend_host }}:{{ expose_frontend_http_port }}"
      MAP_MAIN_BASE_URL: "http://{{ main_ip if (network_mode | default('')) == '' else frontend_host }}:{{ expose_frontend_http_port }}"
      WEB_HANDLER_TIMEOUT: 300
      CIRCLE_RADIUS_COEFFICIENT: 1.3
      ENABLE_POINT_CLUSTER: false
      ENABLE_POINT_ALTITUDE: false
      BASE_TILE_LAYER_MAX_LEVEL: 15
      BASE_TILE_LAYER_MIN_LEVEL: 0
      HAS_SCENE_PREFIX: false
      CANVAS3D_TYPE: "camera"
      MAX_PITCH_ANGLE: 90
      MAX_SCREEN_ERROR: 300
      DEFAULT_GROUND_ALTITUDE: 88
      PITCH_NEGATE_THRESHOLD: 1
    {%- if network_mode is not defined or network_mode == "" %}
    ports:
      - {{ expose_printer_port }}:5890
    {%- endif %}
    volumes:
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime
      - /opt/anbao/map:/opt/anbao/map
      - /opt/anbao/qgz:/opt/anbao/qgz
      - /data:/data
      - /:/fakeRoot
      - /dev:/dev
      - $HOME/.Xauthority:/root/.Xauthority
      - /tmp/.X11-unix:/tmp/.X11-unix
      - /opt/anbao/running/config-prod.yaml:/usr/local/bin/conf/config.yaml
      - /opt/anbao/running/QGIS:/root/.local/share/QGIS
      - /opt/anbao/running/jingweiprinter-stxx:/root/.local/share/stxx
    {%- if network_mode is defined and network_mode %}
    network_mode: {{ network_mode }}
    {%- else %}
    networks:
      - anbao
    {%- endif %}
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 8192M
        reservations:
          cpus: '0.5'
          memory: 1500M
          {%- if have_nvidia_driver %}
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu, utility, compute, video, display]
          {%- endif %}
  {%- endif %}
{%- if network_mode is not defined or network_mode == "" %}
networks:
  anbao:
    external: true
    name: anbao
  default:
    driver: bridge
{%- endif %}
